﻿using System;
using System.Web.Services;
using System.Diagnostics;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Xml.Serialization;

namespace com.huawei.esdk.tp.oa.eSDKTPOAPlatformKeyMgrService
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name = "PlatformKeyMgrServiceSoapBinding", Namespace = "esdk_platform")]
    public partial class PlatformKeyMgrService : System.Web.Services.Protocols.SoapHttpClientProtocol
    {

        private System.Threading.SendOrPostCallback getPublicKeyOperationCompleted;

        //private bool useDefaultCredentialsSetExplicitly;

        /// <remarks/>
        public PlatformKeyMgrService()
        {
            //this.Url = global::esdk_tp_oa_native_cs.Properties.Settings.Default.esdk_tp_oa_native_cs_platformKeyMgr_PlatformKeyMgrService;
            //if ((this.IsLocalFileSystemWebService(this.Url) == true))
            //{
            //    this.UseDefaultCredentials = true;
            //    this.useDefaultCredentialsSetExplicitly = false;
            //}
            //else
            //{
            //    this.useDefaultCredentialsSetExplicitly = true;
            //}
            this.Url = "https://localhost:18543/";
        }

        public PlatformKeyMgrService(string url)
        {
            this.Url = url;
        }

        //public new string Url
        //{
        //    get
        //    {
        //        return base.Url;
        //    }
        //    set
        //    {
        //        if ((((this.IsLocalFileSystemWebService(base.Url) == true)
        //                    && (this.useDefaultCredentialsSetExplicitly == false))
        //                    && (this.IsLocalFileSystemWebService(value) == false)))
        //        {
        //            base.UseDefaultCredentials = false;
        //        }
        //        base.Url = value;
        //    }
        //}

        //public new bool UseDefaultCredentials
        //{
        //    get
        //    {
        //        return base.UseDefaultCredentials;
        //    }
        //    set
        //    {
        //        base.UseDefaultCredentials = value;
        //        this.useDefaultCredentialsSetExplicitly = true;
        //    }
        //}

        /// <remarks/>
        public event getPublicKeyCompletedEventHandler getPublicKeyCompleted;

        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("esdk_platformgetPublicKey", RequestNamespace = "esdk_platform", ResponseNamespace = "esdk_platform", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("resultCode", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public int getPublicKey([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] out string publicKey)
        {
            object[] results = this.Invoke("getPublicKey", new object[0]);
            publicKey = ((string)(results[1]));
            return ((int)(results[0]));
        }

        /// <remarks/>
        public void getPublicKeyAsync()
        {
            this.getPublicKeyAsync(null);
        }

        /// <remarks/>
        public void getPublicKeyAsync(object userState)
        {
            if ((this.getPublicKeyOperationCompleted == null))
            {
                this.getPublicKeyOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetPublicKeyOperationCompleted);
            }
            this.InvokeAsync("getPublicKey", new object[0], this.getPublicKeyOperationCompleted, userState);
        }

        private void OngetPublicKeyOperationCompleted(object arg)
        {
            if ((this.getPublicKeyCompleted != null))
            {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.getPublicKeyCompleted(this, new getPublicKeyCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        /// <remarks/>
        public new void CancelAsync(object userState)
        {
            base.CancelAsync(userState);
        }

        private bool IsLocalFileSystemWebService(string url)
        {
            if (((url == null)
                        || (url == string.Empty)))
            {
                return false;
            }
            System.Uri wsUri = new System.Uri(url);
            if (((wsUri.Port >= 1024)
                        && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0)))
            {
                return true;
            }
            return false;
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    public delegate void getPublicKeyCompletedEventHandler(object sender, getPublicKeyCompletedEventArgs e);

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class getPublicKeyCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
    {

        private object[] results;

        internal getPublicKeyCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
            base(exception, cancelled, userState)
        {
            this.results = results;
        }

        /// <remarks/>
        public int Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((int)(this.results[0]));
            }
        }

        /// <remarks/>
        public string publicKey
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((string)(this.results[1]));
            }
        }
    }
}
